<script>
    //jxt.tag.dataJson = {id: "", type: 'div', cssname:"", tpname:"", jsname:"", init:{}, children: []};
    jxt.tag.newJson = function (dataJson) {

        var json = dataJson;
        var _self = {
            id: "",
            type: json.type
        };
        //      if (json.css) _self.css = json.css;
        //      else {
        //          if (json.cssname) _self.css = json.cssname;
        //      }


        if(json.tpname) _self.tpname = json.tpname ;

        _self.id = "n" + GetRandomNum(10000, 99999);
        if(dataJson.content)_self.content = dataJson.content;
        return _self;
    };
    jxt.tag.render = function (node, edit, noRenderChild, tpname) {
        if ($.type(node) == "string") node = jxt.getnode(node);
        if (!tpname) tpname = jxt.tag.gettpname(node, edit);

        var _html_ = jxt.template(tpname, node);
        var ele = $("#" + node.id);
        ele.replaceWith(_html_);

        if (noRenderChild) return;
        var children = jxt.children(node);
        if (children) {
            for (var i = 0; i < children.length; i++) {
                jxt.render(children[i], edit);
            }
        }

    };

    jxt.tag.gettpname = function (node, edit) {
        var json = node;
        var tpname = (json.tpname) ? json.tpname : ( json.type);
        tpname='jhm_' +tpname;
        if(edit && $.type(edit)=='string' ){
            return tpname + '_'+edit;
        }
        if (!edit) return tpname;
        return tpname + '_edit';

    };

    jxt.tag.children = function (node) {

        var children = [];
        switch ($.type(node)) {
            case "string":
                children.push(node);
                break;
            case "array":
                for (var i = 0; i < node.length; i++) {
                    var _ch = jxt.tag.children(node[i]);
                    if (_ch) children = children.concat(_ch);
                }
                break;
            case "object":
                var _ch = jxt.tag.children(node.children);
                if (_ch) children = children.concat(_ch);

                break;

        }

        return children;
    };

    jxt.tag.add = function (node, newnode, at_id) {
        if (!node.children) {
            node.children = [];
            node.children.push(newnode.id);
            return node;
        }
        var b = false;
        if (at_id) {
            for (var i = 0; i < node.children.length; i++) {
                if (at_id == node.children[i]) {
                    node.children.splice(i + 1, 0, newnode.id);
                    b = true;
                    break;
                }
            }
        }
        if (!b) {
            node.children.push(newnode.id);
        }
        return node;
    };
    jxt.tag.ok = function (eleid) {
        //jxt.msg.aboutSubscribe(eleid, "editbegin");
        jxt.render(eleid, false);
    };
    jxt.tag.del = function (eleid) {
        if (!confirm("del?")) return;
        jxt.delNode(eleid);
        jxt.msg.radio(eleid, "nodechange");
        jxt.msg.aboutSubscribe(jxt.nowlevoneid, "editbegin");
        $("#" + eleid).remove();
    };
    jxt.tag.editbegin = function (eleid, callbackfunction) {
        if (!callbackfunction){
            var node = jxt.getnode(eleid);
            callbackfunction = (node.type)+'.ok' ;
        }
        jxt.msg.radio(eleid, "editbegin");
        jxt.msg.subscribe(eleid, "editbegin", callbackfunction, 'once');
        jxt.render(eleid, true);
    };
    jxt.tag.setNowEditEle = function (eleid) {

        var eid = event.target.id;
        if (eid && eid != eleid) {
            var _eid = jxt.getJXTele(eid);
            if (_eid != eleid) {
                var node = jxt.getnode(eleid);
                if (node) {
                    if(!(node.temp))node.temp={};
                    node.temp.noweditid = _eid;
                }
                //$("#" + eleid).attr("noweditid", _eid);
            }
        }

    };
    jxt.tag.getNowEditEle = function (eleid) {
        var node = jxt.getnode(eleid);
        if (node) {
            return node.temp.noweditid;
        }
        return null;
    };
</script>